package query

import (
	"octopus/hextech/errors"
	"octopus/hextech/message"
	"octopus/user/dto"
	"octopus/user/infra/query"

	"github.com/gin-gonic/gin"
)

func UserInfo(ctx *gin.Context) {
	args := &dto.UserInfoRequest{}
	err := ctx.ShouldBindJSON(args)
	if err != nil {
		message.Failed(ctx, err)
		return
	}

	store := query.NewStore(ctx)
	user, has, err := store.UserInfoByID(args.ID)
	if err != nil {
		message.Failed(ctx, err)
		return
	}
	if !has {
		message.Failed(ctx, errors.New("user not exist"))
		return
	}
	message.Success(ctx, user)
}
